<!--
 * @Author: Vi卡农
 * @Date: 2020-01-13 09:38:57
 * @LastEditTime: 2020-05-11 11:34:51
 * @Description: -录入意向-租-
 * @FilePath: \cshf_admin\src\views\modules\customer\page\intentionleaseinfo-add-or-update.vue
 -->
<template>
  <el-dialog
    :visible.sync="visible"
    :title="!dataForm.id ? $t('add') : $t('update')"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="CloseDialog_"
  >
    <el-form
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmitHandle()"
      label-width="100px"
    >
      <el-row>
        <el-col :span="11">
          <!-- <el-form-item label="交易类型 租赁" prop="transactionType">
                        <el-input v-model="dataForm.transactionType" placeholder="交易类型 租赁"></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="客源类型" prop="customerType">
                        <el-input v-model="dataForm.customerType" placeholder="客源类型"></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="客户id" prop="customerId">
                        <el-input v-model="dataForm.customerId" placeholder="客户id"></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="房源" prop="houseId">
            <el-select
              v-model="dataForm.houseId"
              filterable
              remote
              clearable
              placeholder="请输入关键词"
              :remote-method="remoteMethod"
              :loading="loading"
              class="w100"
            >
              <el-option
                v-for="item in options"
                :key="item.id"
                :label="'FY'+item.id.substring(item.id.length-6)"
                :value="item.id"
                @click.native="houseIdClick(item)"
              ></el-option>
            </el-select>
          </el-form-item>-->
          <!-- <el-form-item
            label="房间id"
            prop="fjId"
          >
            <el-input
              v-model="dataForm.fjId"
              placeholder="房间id"
            ></el-input>
          </el-form-item>-->

          <el-form-item label="房源" prop="houseId">
            <el-input v-model="dataForm.houseId" placeholder="房源" @focus="houseFocus"></el-input>
          </el-form-item>

          <el-form-item label="业主姓名" prop="ownerName">
            <el-input v-model="dataForm.ownerName" placeholder="业主姓名"></el-input>
          </el-form-item>
          <el-form-item label="业主电话" prop="ownerPhone1">
            <el-input v-model="dataForm.ownerPhone1" placeholder="业主电话"></el-input>
          </el-form-item>
          <el-form-item label="业主电话2" prop="ownerPhone2">
            <el-input v-model="dataForm.ownerPhone2" placeholder="业主电话2"></el-input>
          </el-form-item>
          <el-form-item label="业主合同对象" prop="ownerContract">
            <el-input v-model="dataForm.ownerContract" placeholder="业主合同对象"></el-input>
          </el-form-item>
          <el-form-item label="业主税费" prop="ownerTaxation">
            <el-input v-model="dataForm.ownerTaxation" placeholder="业主税费"></el-input>
          </el-form-item>
          <el-form-item label="业主家具" prop="ownerFurniture">
            <el-input v-model="dataForm.ownerFurniture" placeholder="业主家具"></el-input>
          </el-form-item>
          <el-form-item label="业主价格" prop="ownerPrice">
            <el-input v-model="dataForm.ownerPrice" placeholder="业主价格"></el-input>
          </el-form-item>
          <el-form-item label="业主佣金" prop="ownerCommission">
            <el-input v-model="dataForm.ownerCommission" placeholder="业主佣金"></el-input>
          </el-form-item>
          <el-form-item label="业主付款方式" prop="ownerPayType">
            <el-input v-model="dataForm.ownerPayType" placeholder="业主付款方式"></el-input>
          </el-form-item>
          <el-form-item label="业主押金" prop="ownerDeposit">
            <el-input v-model="dataForm.ownerDeposit" placeholder="业主押金"></el-input>
          </el-form-item>
          <el-form-item label="业主税费" prop="csutomerTaxation">
            <el-input v-model="dataForm.csutomerTaxation" placeholder="业主税费"></el-input>
          </el-form-item>
          <el-form-item label="业主免租期" prop="ownerFreeTime">
            <el-input v-model="dataForm.ownerFreeTime" placeholder="业主免租期"></el-input>
          </el-form-item>
          <el-form-item label="业主合同年限" prop="ownerContractTime">
            <el-input v-model="dataForm.ownerContractTime" placeholder="业主合同年限"></el-input>
          </el-form-item>
          <el-form-item label="业主递增" prop="ownerIncrease">
            <el-input v-model="dataForm.ownerIncrease" placeholder="业主递增"></el-input>
          </el-form-item>
          <el-form-item label="是否外佣" prop="external">
            <el-input v-model="dataForm.external" placeholder="是否外佣"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="房源面积" prop="area">
            <el-input v-model="dataForm.area" placeholder="房源面积"></el-input>
          </el-form-item>
          <el-form-item label="客户姓名" prop="customerName">
            <el-input v-model="dataForm.customerName" placeholder="客户姓名"></el-input>
          </el-form-item>
          <el-form-item label="客户电话1" prop="customerPhone1">
            <el-input v-model="dataForm.customerPhone1" placeholder="客户电话1"></el-input>
          </el-form-item>
          <el-form-item label="客户电话2" prop="customerPhone2">
            <el-input v-model="dataForm.customerPhone2" placeholder="客户电话2"></el-input>
          </el-form-item>
          <el-form-item label="业主合同对象" prop="csutomerContract">
            <el-input v-model="dataForm.csutomerContract" placeholder="业主合同对象"></el-input>
          </el-form-item>
          <el-form-item label="客户价格" prop="customerPrice">
            <el-input v-model="dataForm.customerPrice" placeholder="客户价格"></el-input>
          </el-form-item>
          <el-form-item label="客户家具" prop="csutomerFurniture">
            <el-input v-model="dataForm.csutomerFurniture" placeholder="客户家具"></el-input>
          </el-form-item>
          <el-form-item label="客户需求面积" prop="customerArea">
            <el-input v-model="dataForm.customerArea" placeholder="客户需求面积"></el-input>
          </el-form-item>
          <el-form-item label="客户佣金" prop="customerCommission">
            <el-input v-model="dataForm.customerCommission" placeholder="客户佣金"></el-input>
          </el-form-item>
          <el-form-item label="客户付款方式" prop="customerPayType">
            <el-input v-model="dataForm.customerPayType" placeholder="客户付款方式"></el-input>
          </el-form-item>
          <el-form-item label="客户押金" prop="customerDeposit">
            <el-input v-model="dataForm.customerDeposit" placeholder="客户押金"></el-input>
          </el-form-item>
          <el-form-item label="客户免租期" prop="customerFreeTime">
            <el-input v-model="dataForm.customerFreeTime" placeholder="客户免租期"></el-input>
          </el-form-item>
          <el-form-item label="客户合同年限" prop="customerContractTime">
            <el-input v-model="dataForm.customerContractTime" placeholder="客户合同年限"></el-input>
          </el-form-item>
          <el-form-item label="客户递增" prop="customerIncrease">
            <el-input v-model="dataForm.customerIncrease" placeholder="客户递增"></el-input>
          </el-form-item>
          <el-form-item label="意向单状态" prop="state">
            <!-- <el-input v-model="dataForm.state" placeholder="意向单状态"></el-input> -->
            <ren-select
              v-model="dataForm.state"
              dict-type="intentionState"
              placeholder="状态"
              class="FormSelect"
            ></ren-select>
          </el-form-item>

          <el-form-item label="是否重点单" prop="important">
            <el-input v-model="dataForm.important" placeholder="是否重点单"></el-input>
          </el-form-item>
          <!-- <el-form-item label="备注" prop="remark">
                <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="部门id" prop="deptId">
            <el-input v-model="dataForm.deptId" placeholder="部门id"></el-input>
          </el-form-item>-->
          <!-- <el-form-item
            label="城市租户编码"
            prop="tenantCode"
          >
            <el-input
              v-model="dataForm.tenantCode"
              placeholder="城市租户编码"
            ></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="删除状态" prop="deleteFlag">
                <el-input v-model="dataForm.deleteFlag" placeholder="删除状态"></el-input>
            </el-form-item>
            <el-form-item label="修改人" prop="updater">
                <el-input v-model="dataForm.updater" placeholder="修改人"></el-input>
            </el-form-item>
            <el-form-item label="修改时间" prop="updateDate">
                <el-input v-model="dataForm.updateDate" placeholder="修改时间"></el-input>
          </el-form-item>-->
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input
              v-model="dataForm.remark"
              placeholder="备注"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4}"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
    </template>
    <Housing @setHousing="setHousingFun" ref="HousingRef"></Housing>
  </el-dialog>
</template>

<script>
import debounce from "lodash/debounce";
import Housing from "../../Housing/Housing";
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: "",
        dictId:"",
        num:"",
        fjId: "",
        transactionType: "",
        customerType: this.$route.query.customerType,
        customerId: this.$route.query.ID,
        houseId: "",
        area: "",
        ownerName: "",
        ownerPhone1: "",
        ownerPhone2: "",
        ownerContract: "",
        ownerTaxation: "",
        ownerFurniture: "",
        ownerPrice: "",
        ownerCommission: "",
        ownerPayType: "",
        ownerDeposit: "",
        ownerFreeTime: "",
        ownerContractTime: "",
        ownerIncrease: "",
        customerName: "",
        customerPhone1: "",
        customerPhone2: "",
        csutomerContract: "",
        customerPrice: "",
        csutomerTaxation: "",
        csutomerFurniture: "",
        customerArea: "",
        customerCommission: "",
        customerPayType: "",
        customerDeposit: "",
        customerFreeTime: "",
        customerContractTime: "",
        customerIncrease: "",
        state: "",
        external: "",
        important: "",
        remark: "",
        deptId: "",
        tenantCode: "",
        deleteFlag: "",
        creator: "",
        createDate: "",
        updater: "",
        updateDate: ""
      },
      options: [],
      loading: false
    };
  },
  components: {
    Housing
  },
  props: ["CustomerObj"],
  created() {
    if (this.CustomerObj) {
      this.dataForm.customerType = this.CustomerObj.customerType;
      this.dataForm.customerId = this.CustomerObj.id;
      this.dataForm.customerName = this.CustomerObj.customerName;
      this.dataForm.customerPhone1 = this.CustomerObj.customerPhone1;
      this.dataForm.customerPhone2 = this.CustomerObj.customerPhone2;
    }
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      this.$http
        .get(`/intention/intentionleaseinfo/${this.dataForm.id}`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.dataForm = {
            ...this.dataForm,
            ...res.data
          };
        })
        .catch(() => {});
    },
    // 表单提交
    dataFormSubmitHandle: debounce(
      function() {
        this.$refs["dataForm"].validate(valid => {
          if (!valid) {
            return false;
          }
          this.$http[!this.dataForm.id ? "post" : "put"](
            "/intention/intentionleaseinfo/",
            this.dataForm
          )
            .then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            })
            .catch(() => {});
        });
      },
      1000,
      { leading: true, trailing: false }
    ),
    // 选择列表房源
    setHousingFun(obj) {
      // this.dataForm = {
      //   ...this.dataForm,
      //   ...obj
      // };
      this.dataForm.houseId = obj.houseId;
       this.dataForm.dictId = obj.dictId;
      this.dataForm.num = obj.num;
      this.dataForm.houseType = obj.houseType;
      this.dataForm.transactionType = obj.transactionType;
      this.dataForm.fjId = obj.fjId;
      this.dataForm.ownerName = obj.ownerName;
      this.dataForm.ownerPhone1 = obj.ownerPhone1;
      this.dataForm.ownerPhone2 = obj.ownerPhone2;
      this.dataForm.area = obj.area;
    },
    houseFocus() {
      this.$refs.HousingRef.info();
    },
    CloseDialog_() {
      this.$emit("CloseDialog");
    }
  }
};
</script>
